package net.sourceforge.peertwitter.core.events;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.io.IOException;

import org.junit.Test;

import rice.p2p.commonapi.Id;
import rice.p2p.commonapi.NodeHandle;
import rice.p2p.commonapi.rawserialization.OutputBuffer;


public class NodeLeaveTest {
	@Test
	public void twoNodeLeavesAreEqualsWhenTheLeavingNodesAreEqual() {
		final rice.pastry.Id id = rice.pastry.Id.build("0xabcd");
		NodeHandle nodeHandle = new NodeHandle() {

			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public boolean checkLiveness() {
				return false;
			}

			@Override
			public Id getId() {
				return id;
			}

			@Override
			public boolean isAlive() {
				return false;
			}

			@Override
			public int proximity() {
				return 0;
			}

			@Override
			public void serialize(OutputBuffer arg0) throws IOException {
				
			}
			
			
			
		};
		
		NodeLeave leave1 = new NodeLeave(nodeHandle);
		NodeLeave leave2 = new NodeLeave(nodeHandle);
		
		assertEquals(leave1, leave2);
		assertEquals(leave1, leave1);
		assertEquals(leave2, leave2);
	}
	
	@Test
	public void twoNodeLeavesAreNotEqualWhenTheLeavingNodesAreNotEqual() {
		NodeHandle aNodeHandle = new NodeHandle() {

			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public boolean checkLiveness() {
				return false;
			}

			@Override
			public Id getId() {
				return rice.pastry.Id.build("0xdcba");
			}

			@Override
			public boolean isAlive() {
				return false;
			}

			@Override
			public int proximity() {
				return 0;
			}

			@Override
			public void serialize(OutputBuffer arg0) throws IOException {
				
			}
			
		};
		
		NodeHandle aDifferentNodeHandle = new NodeHandle() {

			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public boolean checkLiveness() {
				return false;
			}

			@Override
			public Id getId() {
				return rice.pastry.Id.build("0xabcd");
			}

			@Override
			public boolean isAlive() {
				return false;
			}

			@Override
			public int proximity() {
				return 0;
			}

			@Override
			public void serialize(OutputBuffer arg0) throws IOException {
				
			}
			
		};
		
		NodeLeave leave1 = new NodeLeave(aNodeHandle);
		NodeLeave leave2 = new NodeLeave(aDifferentNodeHandle);
		
		assertFalse(leave1.equals(leave2));
	}
}
